	/*
  AnalogKeypad.h - Library for reading analog keypad
 	 	   from LCD Keypad shield 
  Copyright (c) 2013 Lukas Vavra.  All right reserved.
*/

#include "Arduino.h"
// include this library's description file
#include "AnalogKeypad.h"

// define analog key input intervals from 0

#define ANALOG_RIGHT 50
#define ANALOG_UP 150
#define ANALOG_DOWN 300
#define ANALOG_LEFT 500
#define ANALOG_SELECT 750


// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances

AnalogKeypad::AnalogKeypad(int pin)
{
  // initialize this instance's variables
  keypin = pin;
}

// Public Methods //////////////////////////////////////////////////////////////

int AnalogKeypad::getKey(void)
{
  int value = analogRead(keypin);
  if(value < ANALOG_RIGHT)
    return KEY_RIGHT;
  else if(value < ANALOG_UP)
    return KEY_UP;
  else if(value < ANALOG_DOWN)
    return KEY_DOWN;
  else if(value < ANALOG_LEFT)
    return KEY_LEFT;
  else if(value < ANALOG_SELECT)
    return KEY_SELECT;
  else
    return KEY_NONE;
}

